package com.cass.common;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

    private final JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器，并指定要拦截的路径
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**") // 例如，只拦截/secure路径下的请求
                .excludePathPatterns("/login") // 排除登录接口不被拦截
                .excludePathPatterns("/teacher/**")// 排除登录接口不被拦截
                .excludePathPatterns("/teacher"); // 排除登录接口不被拦截
    }
}
